<?php
include 'inc/config.inc';
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}
$cat = $_GET["catname"];
$insert_qry = mysql_query("INSERT INTO news_categories values (null,'$cat') ");
if ($insert_qry){
	$cat_qry = mysql_query("SELECT * FROM news_categories order by name asc");
	if($cat_qry){
		?>
					<select name="news_cat" id="news_cat" class="span6">
					<option value="">Please select a category...</option>
						<?php 
						while($cat_row=mysql_fetch_array($cat_qry)){
							?>
						<option value="<?php echo $cat_row['id']; ?>"><?php echo $cat_row['name']; ?></option>
														<?
						}
						?>
					</select>
					<a id="add_new_cat" style="margin-left:10px; cursor: hand; cursor:  pointer;">+Add New Category</a>
        <span id="add_new" style="display:none"><input id="cat" type="text" class="span6" placeholder="New category name..."/><input type="button" id="submit_cat" class="btn span2" value="+Add" style="margin-left:10px;"/><input class="btn btn-danger span2" id="cancel" style="margin-left:10px;" value="-Cancel"></span>
										<span class="alert alert-success span6" style="margin-top: 10px; margin-left:0; margin-down:0;">Category Added Successfully!</span>
					<?
				}	
}
else {
	?>
	<select name="news_cat" id="news_cat" class="span6">
					<option value="">Please select a category...</option>
						<?php 
						while($cat_row=mysql_fetch_array($cat_qry)){
							?>
						<option value="<?php echo $cat_row['id']; ?>"><?php echo $cat_row['name']; ?></option>
														<?
						}
						?>
					</select>
					<a id="add_new_cat" style="margin-left:10px; cursor: hand; cursor:  pointer;">+Add New Category</a>
					<span id="add_new" style="display:none"><input id="cat" type="text" class="span6" placeholder="Enter the name for new category..."/><input type="button" id="submit_cat" class="btn" value="+Add" style="margin-left:10px;"/><a id="cancel" style="margin-left:10px; cursor: hand; cursor:  pointer;">-Cancel</a></span>
					<span class="alert alert-error span6" style="margin-top: 10px; margin-left:0; margin-down:0;">Error! NOT Added!</span>
	<?
}
?>